﻿using Basic.FormCollect;
using Basic.FormModel.DB;
using Basic.FormRemoteModel.PageControl;
using Basic.FormRemoteModel.PageControl.Model;
using Basic.FormService.Model;
using WeDonekRpc.Client;
using WeDonekRpc.Client.Interface;
using WeDonekRpc.Helper;

namespace Basic.FormService.RpcEvent
{
    internal class PageControlEvent : IRpcApiService
    {
        private readonly IPageControlCollect _Service;

        public PageControlEvent ( IPageControlCollect service )
        {
            this._Service = service;
        }

        public PageControlItem[] GetPageControlItem ( GetPageControlItem obj )
        {
            PageControlItemDto[] list = this._Service.GetItems<PageControlItemDto>();
            if ( list.IsNull() )
            {
                return null;
            }
            return list.ConvertAll(a => new PageControlItem
            {
                Classify = a.Classify,
                Description = a.Description,
                Code = a.Code,
                ControlPath = obj.IsEdit ? a.EditControlPath : a.ControlPath,
                ControlType = a.ControlType,
                Icon = a.Icon,
                Id = a.Id,
                MinHeight = a.MinHeight,
                MinWidth = a.MinWidth,
                Name = a.Name
            });
        }

        public PageControlDto GetPageControl ( GetPageControl obj )
        {
            DBPageControl db = this._Service.Get<DBPageControl>(obj.Id);
            return db.ConvertMap<DBPageControl, PageControlDto>();
        }
    }
}
